package com.bbx.taxi.client.Task;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.official.passanger.Officail_ComboBuild;
import com.bbx.api.sdk.model.official.passanger.Official_AABuild;
import com.bbx.api.sdk.model.official.passanger.Official_AABuild;
import com.bbx.api.sdk.model.official.passanger.Official_AABuild.OrginFos;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Combo;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_TC;
import com.bbx.api.sdk.model.official.passanger.Return.Official_AA;
import com.bbx.api.sdk.model.official.passanger.Return.Official_Star;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Officail_ComboNet;
import com.bbx.api.sdk.net.official.passanger.Official_AANet;
import com.bbx.api.sdk.net.official.passanger.Official_StarNet;
import com.bbx.api.sdk.net.official.passanger.Official_TCNet;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Task.BaseAsyncTask;
import com.bbx.taxi.client.Task.MyOperateTask.OnOperateStatusListener;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.official.R;
/** 
 * @Path com.bbx.taxi.client.Task.MyAATask.java
 * @Author 严旭文
 * @Date 2016-4-5 上午11:24:10
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class MyAATask  {
	public static int STATUS_SUCCESS=0;
	public static int STATUS_FAIL=-1;
	private Activity context;
	public static MyAATask instance;
	public AATask mAATask;
	public interface OnAAFinishListener {
		/**
		 *status 0为成功
		 */
		public void onAAFinish(int status);
	}

	static OnAAFinishListener mOnAAFinishListener = null;

	public static void setOnAAFinishListener(OnAAFinishListener l) {
		mOnAAFinishListener = l;
	}
	public static MyAATask getInstance(Activity context,String order_id,List<OrginFos> list) {
		instance = new MyAATask(context,order_id,list);
		return instance;
	}
	public MyAATask(Activity context,String order_id,List<OrginFos> list) {
		this.context = context;
		setAA(order_id,list);
	
	}
	/**
	 * AA制
	 */
	public void setAA(String order_id,List<OrginFos> list) {
		Official_AABuild mOfficial_AABuild=new Official_AABuild(context);
		mOfficial_AABuild.passenger_id=MyApplication.getInstance().getUid();
		mOfficial_AABuild.order_id=order_id;
		mOfficial_AABuild.orginfos=list;
		AATask mAATask=new AATask(context, mOfficial_AABuild);
		mAATask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	private class AATask extends BaseAsyncTask {

		private Official_AABuild mOfficial_AABuild;

		public AATask(Activity context, Official_AABuild mOfficial_AABuild) {
			super(context,true);
			this.mOfficial_AABuild = mOfficial_AABuild;
		}

		@Override
		public void onSuccess(Object object) {
			if (object != null) {
				Official_AA mOfficial_AA=(Official_AA)object;
				if(mOfficial_AA!=null){
				     if(mOnAAFinishListener!=null)mOnAAFinishListener.onAAFinish(STATUS_SUCCESS);
				}else{
					ToastUtil.showToast(context, R.string.no_network);
					if(mOnAAFinishListener!=null)mOnAAFinishListener.onAAFinish(STATUS_FAIL);
				}
			}else{
				ToastUtil.showToast(context, R.string.no_network);
				if(mOnAAFinishListener!=null)mOnAAFinishListener.onAAFinish(STATUS_FAIL);
			}
		}

		@Override
		public void onFailed(int status, String msg) {
			try {
				JSONObject jso=new JSONObject(msg);
				ToastUtil.showToast(context, jso.getString("message"));
			} catch (JSONException e) {
				e.printStackTrace();
			}
			if(mOnAAFinishListener!=null)mOnAAFinishListener.onAAFinish(STATUS_FAIL);
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOfficial_AABuild).getJson();
			return new Official_AANet(context, json);
		}
	}

}
